package com.ithe.practice;

import java.util.Comparator;
import java.util.Scanner;
import java.util.TreeSet;

public class TreeSetPratise {
    public static void main(String[] args) {
/**
 * 1.创建一个TreeSet集合
 * 创建person对象
 * 建立for循环，循环3次
 * 5。遍历TreeSet集合，打印集合中的元素
 *
 * */

        TreeSet<Person> ts = new TreeSet<>(new Comparator<Person>() {
            @Override
            public int compare(Person o1, Person o2) {
                return (int) (o2.getMath() + o2.getChinese() + o2.getEnglish() - o1.getChinese() - o1.getMath() - o1.getEnglish());
            }
        });
        Scanner scanner = new Scanner(System.in);


        int i;
        for (i = 0; i < 3; i++) {
        System.out.println("请输入第" + (i + 1) + "个学生信息：");
        System.out.println("请输入姓名");

        String name = scanner.next();
        System.out.println("请输入语文成绩");
        double Chinese = scanner.nextDouble();
        System.out.println("请输入数学成绩");
        double Math = scanner.nextDouble();
        System.out.println("请输入英语成绩");
        double English = scanner.nextDouble();

        Person P = new Person(name, Chinese, Math, English);
        ts.add(P);
    }
    for (Person P : ts){
        System.out.println(P);
    }
    }
}

